package com.company.cloud.club.modules.controller;

import com.company.cloud.club.modules.core.dto.Result;
import com.company.cloud.club.modules.dto.ticket.OrderByProductSingleSaveParam;
import com.company.cloud.club.modules.dto.ticket.UserRegisterParam;
import com.company.cloud.club.modules.dto.ticket.UserUpdateParam;
import com.company.cloud.club.modules.service.TicketService;
import com.company.cloud.club.modules.utils.LoginContextUtils;
import com.company.cloud.common.auth.annotation.Login;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginUserInfo;
import com.company.cloud.common.utils.AuthContextUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "门票系统")
@RequestMapping("/ticket")
@RestController
public class TicketController {

    @Autowired
    private TicketService ticketService;

    @PostMapping("/access_token/generate")
    @ApiOperation(value = "生成AccessToken")
    public Result generateAccessToken() {
        String token = ticketService.generateAccessToken();
        return Result.ok(token);
    }

    @PostMapping("/register")
    @ApiOperation(value = "手机注册-不登录")
    public Result registerByMobileNotLogin(@RequestBody UserRegisterParam params) {
        ticketService.validateToken(LoginContextUtils.getToken());
        String str = ticketService.registerByMobileNotLogin(params);
        return Result.ok(str);
    }

    @PostMapping("/user_info/update")
    @ApiOperation(value = "更新用户信息")
    public Result updateUserInfo(@RequestBody UserUpdateParam params) {
        ticketService.validateToken(LoginContextUtils.getToken());
        String str = ticketService.updateUserInfo(params);
        return Result.ok(str);
    }

    @PostMapping("/order/save")
    @ApiOperation(value = "保存订单信息")
    public Result registerByMobileNotLogin(@RequestBody OrderByProductSingleSaveParam params) {
        ticketService.validateToken(LoginContextUtils.getToken());
        String str = ticketService.saveByProductSingle(params);
        return Result.ok(str);
    }

}
